<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="APT (Advanced Packaging Tool)  apt = apt-get 、 apt-cache 、 apt-config 最常用命令选项的集合 aptitude 是一个带 UI 的管理工具，也可以非 UI 方式运行  常用命令 # 查看帮助 $ sudo apt help # 查找软件包 $ sudo apt list | grep &lt;package&gt; # 查找已安装的包 $ sudo apt list &lt;package&gt; # 安装 $ sudo apt install &lt;package&gt; $ sudo apt reinstall &lt;package&gt; # 卸载 $ sudo apt remove &lt;package&gt; # 删除未使用到的包 $ sudo apt autoremove # 查看包信息 $ sudo apt show -a &lt;package&gt; # 查看日志 $ tail -fn 200 /var/log/apt/history."><meta property="og:title" content="apt" />
<meta property="og:description" content="APT (Advanced Packaging Tool)  apt = apt-get 、 apt-cache 、 apt-config 最常用命令选项的集合 aptitude 是一个带 UI 的管理工具，也可以非 UI 方式运行  常用命令 # 查看帮助 $ sudo apt help # 查找软件包 $ sudo apt list | grep &lt;package&gt; # 查找已安装的包 $ sudo apt list &lt;package&gt; # 安装 $ sudo apt install &lt;package&gt; $ sudo apt reinstall &lt;package&gt; # 卸载 $ sudo apt remove &lt;package&gt; # 删除未使用到的包 $ sudo apt autoremove # 查看包信息 $ sudo apt show -a &lt;package&gt; # 查看日志 $ tail -fn 200 /var/log/apt/history." />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://hello-world-example.github.io/linux/docs/200_Command/270_Package/Apt/" />
<meta property="article:modified_time" content="2022-12-11T01:38:37+08:00" />
<title>apt | Linux</title>
<link rel="icon" href="/linux/favicon.png" type="image/x-icon">


<link rel="stylesheet" href="/linux/book.min.00b8e784201abfe629a6e0741e94bf44575af8612aec171d94e4ecbd3692cf5c.css" integrity="sha256-ALjnhCAav&#43;YppuB0HpS/RFda&#43;GEq7BcdlOTsvTaSz1w=">


<!--
Made with Book Theme
https://github.com/alex-shpak/hugo-book
-->

  
</head>

<body>
  <input type="checkbox" class="hidden" id="menu-control" />
  <main class="container flex">
    <aside class="book-menu">
      
  <nav>
<h2 class="book-brand">
  <a href="/linux"><span>Linux</span>
  </a>
</h2>












  

  
  





 
  
    




  
  <ul>
    
      
        

  <li>
    

  
  <a href="/linux/docs/100_Shell/" class="collapsed ">Shell</a>
  


    






  </li>


      
    
      
        

  <li>
    

  
  <a href="/linux/docs/200_Command/" class="collapsed ">Command</a>
  


    




  
  <ul>
    
      
        

  <li>
    

  
  <a href="/linux/docs/200_Command/210_Common/" class="collapsed ">常用工具</a>
  


    






  </li>


      
    
      
        

  <li>
    

  
  <a href="/linux/docs/200_Command/220_Troubleshooting/" class="collapsed ">故障排查</a>
  


    






  </li>


      
    
      
        

  <li>
    

  
  <a href="/linux/docs/200_Command/230_Network/" class="collapsed ">Network</a>
  


    






  </li>


      
    
      
        

  <li>
    

  
  <a href="/linux/docs/200_Command/240_Disk/" class="collapsed ">磁盘</a>
  


    






  </li>


      
    
      
        

  <li>
    

  
  <a href="/linux/docs/200_Command/250_String/" class="collapsed ">字符串操作</a>
  


    






  </li>


      
    
      
        

  <li>
    

  
  <a href="/linux/docs/200_Command/260_Auth/" class="collapsed ">账户权限</a>
  


    






  </li>


      
    
      
        

  <li>
    

  
  <a href="/linux/docs/200_Command/270_Package/" class="collapsed ">Package..</a>
  


    




  
  <ul>
    
      
        <li>

  
  <a href="/linux/docs/200_Command/270_Package/rpm/" class="">rpm</a>
  

</li>
      
    
      
        <li>

  
  <a href="/linux/docs/200_Command/270_Package/yum/" class="">yum</a>
  

</li>
      
    
      
        <li>

  
  <a href="/linux/docs/200_Command/270_Package/Dpkg/" class="">dpkg</a>
  

</li>
      
    
      
        <li>

  
  <a href="/linux/docs/200_Command/270_Package/Apt/" class="active">apt</a>
  

</li>
      
    
  </ul>
  



  </li>


      
    
      
        

  <li>
    

  
  <a href="/linux/docs/200_Command/280_System/" class="collapsed ">系统管理</a>
  


    






  </li>


      
    
      
        

  <li>
    

  
  <a href="/linux/docs/200_Command/290_Compression/" class="collapsed ">解压缩</a>
  


    






  </li>


      
    
  </ul>
  



  </li>


      
    
      
        

  <li>
    

  
  <a href="/linux/docs/300_Configuration/" class="collapsed ">文件和配置</a>
  


    






  </li>


      
    
      
        

  <li>
    

  
  <a href="/linux/docs/900_FAQ/" class="">FAQ</a>
  


    




  
  <ul>
    
  </ul>
  



  </li>


      
    
      
        

  <li>
    

  
  <a href="/linux/docs/999_Links/" class="">Links 🔗</a>
  


    




  
  <ul>
    
  </ul>
  



  </li>


      
    
  </ul>
  



  
















</nav>




  <script>(function(){var menu=document.querySelector("aside.book-menu nav");addEventListener("beforeunload",function(event){localStorage.setItem("menu.scrollTop",menu.scrollTop);});menu.scrollTop=localStorage.getItem("menu.scrollTop");})();</script>


 
    </aside>

    <div class="book-page">
      <header class="book-header">
        
  <div class="flex align-center justify-between">
  <label for="menu-control">
    <img src="/linux/svg/menu.svg" class="book-icon" alt="Menu" />
  </label>

  <strong>apt</strong>

  <label for="toc-control">
    <img src="/linux/svg/toc.svg" class="book-icon" alt="Table of Contents" />
  </label>
</div>


  
    <input type="checkbox" class="hidden" id="toc-control" />
    <aside class="hidden clearfix">
      
  <nav id="TableOfContents">
  <ul>
    <li><a href="#apt-advanced-packaging-tool">APT (Advanced Packaging Tool)</a>
      <ul>
        <li><a href="#常用命令">常用命令</a></li>
        <li><a href="#更新">更新</a></li>
        <li><a href="#相关文件">相关文件</a></li>
        <li><a href="#sourceslist-文件格式">sources.list 文件格式</a></li>
        <li><a href="#替换国内源">替换国内源</a></li>
        <li><a href="#read-more">Read More</a></li>
      </ul>
    </li>
  </ul>
</nav>


    </aside>
  
 
      </header>

      
      
  <article class="markdown"><h1 id="apt-advanced-packaging-tool">APT (Advanced Packaging Tool)</h1>
<ul>
<li><code>apt</code> = <code>apt-get</code> 、 <code>apt-cache</code> 、 <code>apt-config</code> 最常用命令选项的集合</li>
<li><code>aptitude</code> 是一个带 UI 的管理工具，也可以非 UI 方式运行</li>
</ul>
<h2 id="常用命令">常用命令</h2>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash"><span style="color:#75715e"># 查看帮助</span>
$ sudo apt help

<span style="color:#75715e"># 查找软件包</span>
$ sudo apt list | grep &lt;package&gt;
<span style="color:#75715e"># 查找已安装的包</span>
$ sudo apt list &lt;package&gt;

<span style="color:#75715e"># 安装</span>
$ sudo apt install &lt;package&gt;
$ sudo apt reinstall &lt;package&gt;

<span style="color:#75715e"># 卸载</span>
$ sudo apt remove &lt;package&gt;
<span style="color:#75715e"># 删除未使用到的包</span>
$ sudo apt autoremove

<span style="color:#75715e"># 查看包信息</span>
$ sudo apt show -a &lt;package&gt;

<span style="color:#75715e"># 查看日志</span>
$ tail -fn <span style="color:#ae81ff">200</span> /var/log/apt/history.log
</code></pre></div><h2 id="更新">更新</h2>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash"><span style="color:#75715e"># 更新源</span>
$ sudo apt update

<span style="color:#75715e"># 查看可用的更新</span>
$ sudo apt list --upgradable

<span style="color:#75715e"># 升级所有可升级的软件包</span>
$ sudo apt upgrade

<span style="color:#75715e"># ❤ 在升级软件包时自动处理依赖关系</span>
$ sudo apt full-upgrade
</code></pre></div><h2 id="相关文件">相关文件</h2>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash"><span style="color:#75715e"># 软件源的地址</span>
$ /etc/apt/sources.list

<span style="color:#75715e"># 已经下载到的软件包都放在这里</span>
$ /var/cache/apt/archives
</code></pre></div><blockquote>
<p>Ubuntu 镜像使用帮助 
  <a href="http://mirrors.163.com/.help/ubuntu.html">http://mirrors.163.com/.help/ubuntu.html</a></p>
</blockquote>
<h2 id="sourceslist-文件格式">sources.list 文件格式</h2>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash"><span style="color:#75715e"># 当前系统版本</span>
$ lsb_release -a
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.1 LTS
Release:        20.04
Codename:       focal

<span style="color:#75715e"># 源文件示例</span>
$ vim /etc/apt/sources.list
...
deb http://us.archive.ubuntu.com/ubuntu/ focal main restricted
<span style="color:#75715e"># deb-src http://us.archive.ubuntu.com/ubuntu/ focal main restricted</span>
deb http://us.archive.ubuntu.com/ubuntu/ focal-updates main restricted
...
deb http://us.archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
...
</code></pre></div><p>可以通过 <code>man sources.list</code> 查看帮助，格式为：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">deb <span style="color:#f92672">[</span> option1<span style="color:#f92672">=</span>value1 option2<span style="color:#f92672">=</span>value2 <span style="color:#f92672">]</span> uri suite <span style="color:#f92672">[</span>component1<span style="color:#f92672">]</span> <span style="color:#f92672">[</span>component2<span style="color:#f92672">]</span> <span style="color:#f92672">[</span>...<span style="color:#f92672">]</span>
deb-src <span style="color:#f92672">[</span> option1<span style="color:#f92672">=</span>value1 option2<span style="color:#f92672">=</span>value2 <span style="color:#f92672">]</span> uri suite <span style="color:#f92672">[</span>component1<span style="color:#f92672">]</span> <span style="color:#f92672">[</span>component2<span style="color:#f92672">]</span> <span style="color:#f92672">[</span>...<span style="color:#f92672">]</span>
</code></pre></div><ul>
<li><strong>Types</strong>  可以为 <code>deb</code> 、<code>deb-src</code></li>
<li><strong>URIs</strong>:  支持 <code>http</code>、 <code>ftp</code>、 <code>file</code> 等</li>
<li><strong>Suites</strong>:  是 Ubuntu 的版本代号，通过 <code>lsb_release -sc</code> 获取，这里是 <code>focal</code>
<ul>
<li><code>focal-updates</code> 推荐更新</li>
<li><code>focal-security</code>  重要的安全更新</li>
<li><code>focal-backports</code> 不支持的更新</li>
<li><code>focal-proposed</code> 预发布更新</li>
</ul>
</li>
<li><strong>Components&hellip;</strong> 可以写多个，是 <a href="http://mirrors.163.com/ubuntu/dists/focal/">http://mirrors.163.com/ubuntu/dists/focal/</a> 下的子文件夹
<ul>
<li><code>main</code> 完全的自由软件</li>
<li><code>restricted</code> 不完全的自由软件</li>
<li><code>universe</code> 全靠社区支持的补丁</li>
<li><code>muitiverse</code> 非自由软件，完全不提供支持和补丁</li>
</ul>
</li>
<li>下载 <a href="http://mirrors.163.com/ubuntu/dists/focal/main/binary-amd64/Packages.gz">http://mirrors.163.com/ubuntu/dists/focal/main/binary-amd64/Packages.gz</a> 解压后查看，文件内容是包的索引，如下：
<ul>
<li>与 <code>cat /var/lib/dpkg/status</code> 内容类似</li>
</ul>
</li>
</ul>
<pre><code>Package: accountsservice
Architecture: amd64
Version: 0.6.55-0ubuntu11
Priority: standard
Section: gnome
Origin: Ubuntu
...
Depends: dbus, libaccountsservice0 (= 0.6.55-0ubuntu11), libc6 (&gt;= 2.4), libglib2.0-0 (&gt;= 2.44), libpolkit-gobject-1-0 (&gt;= 0.99)
Suggests: gnome-control-center
Filename: pool/main/a/accountsservice/accountsservice_0.6.55-0ubuntu11_amd64.deb
Size: 60940
MD5sum: 87a0e27c83950d864d901ceca0f2b49c
...

Package: acct
Architecture: amd64
Version: 6.6.4-2
...
</code></pre><h2 id="替换国内源">替换国内源</h2>
<blockquote>
<ul>
<li>以下为 aliyun 的 Ubuntu 20.04(focal) 版本的 <code>sources.list</code>， 可对比以上格式说明进行理解</li>
<li><a href="https://developer.aliyun.com/mirror/ubuntu">https://developer.aliyun.com/mirror/ubuntu</a></li>
</ul>
</blockquote>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
</code></pre></div><h2 id="read-more">Read More</h2>
<ul>
<li>
  <a href="https://wiki.debian.org/SourcesList">SourcesList</a></li>
<li>
  <a href="https://manpages.debian.org/jessie/apt/sources.list.5.en.html">SOURCES.LIST(5)</a></li>
</ul>
</article>
 
      

      <footer class="book-footer">
        
  <div class="flex justify-between">



  <div>
    
    <a class="flex align-center" href="https://github.com/hello-world-example/Linux/commit/d07f642a1d3d369f2ee692c45224763cdf4a7f29" title='Last modified by kaibin.yang | Dec 11, 2022' target="_blank" rel="noopener">
      <img src="/linux/svg/calendar.svg" class="book-icon" alt="Calendar" />
      <span>Dec 11, 2022</span>
    </a>
  </div>



  <div>
    <a class="flex align-center" href="https://github.com/hello-world-example/Linux/edit/master/HuGo/content/docs/200_Command/270_Package/Apt.md" target="_blank" rel="noopener">
      <img src="/linux/svg/edit.svg" class="book-icon" alt="Edit" />
      <span>Edit this page</span>
    </a>
  </div>

</div>

 
        <script>
    var images = document.getElementsByTagName("img")
    for (var i = 0; i < images.length; i++) {
        var image = images[i]
        var src = image.getAttribute("src");
         
        if (src.startsWith("-images")) {
            image.setAttribute("src", "../" + src)
        }
         
        if (window.location.href.indexOf("/posts/")) {
            src = src.replace("../drawio/", "../../drawio/")
            image.setAttribute("src", src)
        }
         
        if (src.startsWith("../drawio/")) {
            image.setAttribute("src", src.replace("../drawio/", "../"))
        }

         
        if(src.indexOf("/svg/") < 0){
             
            image.onclick = function (e) {
                window.open(e.target.getAttribute("src"))
            }
        }
    }

</script>

      </footer>

      
  
  <div class="book-comments">

</div>
  
 

      <label for="menu-control" class="hidden book-menu-overlay"></label>
    </div>

    
    <aside class="book-toc">
      
  <nav id="TableOfContents">
  <ul>
    <li><a href="#apt-advanced-packaging-tool">APT (Advanced Packaging Tool)</a>
      <ul>
        <li><a href="#常用命令">常用命令</a></li>
        <li><a href="#更新">更新</a></li>
        <li><a href="#相关文件">相关文件</a></li>
        <li><a href="#sourceslist-文件格式">sources.list 文件格式</a></li>
        <li><a href="#替换国内源">替换国内源</a></li>
        <li><a href="#read-more">Read More</a></li>
      </ul>
    </li>
  </ul>
</nav>

 
    </aside>
    
  </main>

  
</body>

</html>












